<template>
  <div id="centerLeft1">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span style="color:#5cd9e8">
          <icon name="chart-bar"></icon>
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">各州死亡人数</span>
          <dv-decoration-3 style="width:1.25rem;height:.25rem; position:relative;top:-.0375rem;" />
        </div>
      </div>
      <div class="d-flex jc-center">
        <CenterLeft1Chart :datas="datas"/>
      </div>
      <!-- 4个主要的数据 -->
      <div class="bottom-data">
        <div class="item-box" v-for="(item,index) in numberData" :key="index">
          <div class="d-flex">
            <!--<span class="coin">유</span>-->
            <dv-digital-flop :config="item.number" style="width:2.5rem;height:.625rem;font-size: 15px" />
          </div>
          <p class="text" style="text-align: center;">
            {{item.text}}
            <span class="colorYellow">(人)</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CenterLeft1Chart from "@/components/echart/centerLeft/centerLeft1Chart";
export default {
  data() {
    return {
      datas : {},
      numberData: [
        {
          number: {
            number: [0],
            toFixed: 0,
            content: "{nt}"
          },
          text: "新增确诊人数"
        },
        {
          number: {
            number: [0],
            toFixed: 0,
            content: "{nt}"
          },
          text: "总确诊人数"
        },
        {
          number: {
            number: [0],
            toFixed: 0,
            content: "{nt}"
          },
          text: "新增死亡人数"
        },
        {
          number: {
            number: [0],
            toFixed: 0,
            content: "{nt}"
          },
          text: "总死亡人数"
        }
      ]
    };
  },
  components: {
    CenterLeft1Chart
  },
  mounted() {
    this.getdata();
  },
  methods: {
    async getdata(){
      let self = this;
      this.$http.get('http://116.196.92.193:8090/data/getDeaths', {
        params: {
        }
      }).then(function (response) {
        //console.log(response);
        var n1 = response.data.data.sumcase;
        var n2 = response.data.data.sumdeath;
        var n3 = response.data.data.sumaddcase;
        var n4 = response.data.data.sumadddeath;
        self.numberData[0].number.number[0] = n3;
        self.numberData[0].number = { ...self.numberData[0].number };
        self.numberData[1].number.number[0] = n1;
        self.numberData[1].number = { ...self.numberData[1].number };
        self.numberData[2].number.number[0] = n4;
        self.numberData[2].number = { ...self.numberData[2].number };
        self.numberData[3].number.number[0] = n2;
        self.numberData[3].number = { ...self.numberData[3].number };
        var mapdata = response.data.data.map;
        var xData = [];
        var seriesData = [];
        for(var k in mapdata){
          xData.push(k);
          seriesData.push({value: mapdata[k], name: k});
        }
        self.datas = {
          xData: xData,
          seriesData: seriesData
        }
      }).catch(function (error) {
        console.log(error);
      });
    },
    changeTiming() {
      setInterval(() => {
        this.changeNumber();
      }, 3000);
    },
    changeNumber() {
      this.numberData.forEach((item, index) => {
        item.number.number[0] += ++index;
        item.number = { ...item.number };
      });
    }
  }
};
</script>

<style lang="scss">
#centerLeft1 {
  padding: 0.2rem;
  height: 5.125rem;
  min-width: 3.75rem;
  border-radius: 0.0625rem;
  .bg-color-black {
    height: 4.8125rem;
    border-radius: 0.125rem;
  }
  .text {
    color: #c3cbde;
  }
  .chart-box {
    margin-top: 0.2rem;
    width: 2.125rem;
    height: 2.125rem;
    .active-ring-name {
      padding-top: 0.125rem;
    }
  }

  .bottom-data {
    .item-box {
      float: right;
      position: relative;
      width: 50%;
      color: #d3d6dd;
      // 金币
      .coin {
        position: absolute;
        left: 0.1rem;
        top: 0.2125rem;
        font-size: 0.25rem;
        color: #ffc107;
      }
      .colorYellow {
        color: yellowgreen;
      }
    }
  }
}
</style>
